//
//  OYComposeButton.swift
//  weiboCopycat
//
//  Created by Orange Yu on 2016/12/8.
//  Copyright © 2016年 Orange Yu. All rights reserved.
//

import UIKit

class OYComposeButton: UIButton {
    
    
    /// 重写highLighted的getter和setter可以让button在修改transform的时候不会调用LayoutSubviews
    override var isHighlighted: Bool {
        get {
            return false
        }
        set {
            // 空实现
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        imageView?.contentMode = .center
        
        titleLabel?.textAlignment = .center
        self.setTitleColor(UIColor.darkGray, for: .normal)
        titleLabel?.font = UIFont.systemFont(ofSize: 12)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    /// 重新对button进行布局，将布局修改为上图下文
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        imageView?.width = width
        imageView?.height = width
        imageView?.y = 0
        
        titleLabel?.width = width
        titleLabel?.height = height - width
        titleLabel?.x = 0
        titleLabel?.y = width
        
    }
  
}
